<!-- @format -->

<!--用户管理-->
<template>
	<div class="page-container">
		<ex_super_table_page v-bind="option" ref="SuperTablePage">
			<template v-slot:userExtend="{ row }">
				<div style="display: flex; align-items: center;">
					<el-tooltip v-if="showSyncDeptBtn && thirdLoginType == 'WECHAT' && row.openId && row.openId != ''" class="item" effect="light" content="已绑定企业微信" placement="top-start">
						<img src="//kyb-bronze-public-oss.oss-cn-shenzhen.aliyuncs.com/icon/wechat_icon.png" style="height: 16px; margin-right: 6px; " />
					</el-tooltip>

					<template v-if="row.dataLevel == 'DEPT'">
						<el-tooltip class="item" effect="light" :content="'数据权限: ' + $tt('UmsDataLevelEnum__' + row.dataLevel)" placement="top-start">
							<span style="color: #2d8ae5;  border: 1px solid #2d8ae5;  padding: 1px 6px; border-radius: 6px; margin-right: 10px; word-break: keep-all;">{{
								$tt('UmsDataLevelEnum__' + row.dataLevel)
							}}</span>
						</el-tooltip>
					</template>

					<template v-if="row.dataLevel == 'ADMIN'">
						<el-tooltip class="item" effect="light" :content="'数据权限: ' + $tt('UmsDataLevelEnum__' + row.dataLevel)" placement="top-start">
							<span style="border: 1px solid #2d8ae5; color: #2d8ae5;  padding: 1px 6px; border-radius: 6px; margin-right: 10px; word-break: keep-all;">{{
								$tt('UmsDataLevelEnum__' + row.dataLevel)
							}}</span>
						</el-tooltip>
					</template>
				</div>
			</template>
		</ex_super_table_page>

		<el-dialog :title="dialogTitle" :visible.sync="dialogFormVisible" width="880px" height="200px" :close-on-click-modal="false">
			<el-form ref="formEl" :model="formValue" :rules="rules" label-width="120px" class="common-form-panel-div" style="padding: 0px 10px;">
				<ex_header_spiler :title="$tt('label_srm_contract_management_basic_info')"></ex_header_spiler>

				<el-row>
					<el-col>
						<el-form-item :label="$tt('label_login_account')" prop="loginId">
							<el-input v-model="formValue.loginId"></el-input>
						</el-form-item>
					</el-col>
					<!--          <el-col>-->
					<!--            <el-form-item label="职位" prop="position">-->
					<!--              <el-input v-model="formValue.position"></el-input>-->
					<!--            </el-form-item>-->
					<!--          </el-col>-->

					<el-col>
						<el-form-item :label="$tt('label_tms_user_name')" prop="name">
							<el-input v-model="formValue.name"></el-input>
						</el-form-item>
					</el-col>
				</el-row>

				<el-row>
					<el-col>
						<el-form-item :label="$tt('label_phone_number')">
							<el-input v-model="formValue.mobile"></el-input>
						</el-form-item>
					</el-col>
					<el-col>
						<el-form-item :label="$tt('label_mailbox')">
							<el-input v-model="formValue.email"></el-input>
						</el-form-item>
					</el-col>
				</el-row>

				<el-row v-if="roleSystem != 'WMS'">
					<el-col>
						<el-form-item :label="$tt('label_data_level')">
							<el-select v-model="formValue.dataLevel" clearable style="width:100%;">
								<el-option :label="$tt('UmsDataLevelEnum__ADMIN')" value="ADMIN"></el-option>
								<el-option :label="$tt('UmsDataLevelEnum__DEPT')" value="DEPT"></el-option>
								<el-option :label="$tt('UmsDataLevelEnum__COMMON')" value="COMMON"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col>
						<el-form-item style="color: #999;" labelWidth="12px">
							<template v-if="formValue.dataLevel === 'ADMIN'"><i class="el-icon-warning" style="margin-right: 8px;"></i>可查看所有数据 </template>
							<template v-if="formValue.dataLevel === 'DEPT'"><i class="el-icon-warning" style="margin-right: 8px;"></i>可查看自己部门的数据 </template>
							<template v-if="formValue.dataLevel === 'COMMON'"><i class="el-icon-warning" style="margin-right: 8px;"></i>仅能查看与自己有关的数据 </template>
						</el-form-item>
					</el-col>
				</el-row>

				<el-row>
					<el-col>
						<el-form-item label="所在部门" prop="deptIdInput">
							<el-cascader v-model="formValue.deptIdInput" :options="deptOptions" :props="{ checkStrictly: true, label: 'name', value: 'id' }" style="width: 100%;" clearable></el-cascader>
						</el-form-item>
					</el-col>
					<el-col>
						<el-form-item label="" labelWidth="12px">
							<el-button icon="el-icon-plus" @click="formValue.deptIdsInput.push([])" type="text">添加兼职部门</el-button>
						</el-form-item>
					</el-col>
				</el-row>
				<el-row v-for="(item, index) in formValue.deptIdsInput" :key="'dept_' + index">
					<el-col>
						<el-form-item :label="'兼职部门 ' + (index + 1)">
							<el-cascader v-model="formValue.deptIdsInput[index]" :options="deptOptions" :props="{ checkStrictly: true, label: 'name', value: 'id' }" style="width: 100%;" clearable></el-cascader>
						</el-form-item>
					</el-col>
					<el-col>
						<el-form-item label="" labelWidth="12px">
							<el-button icon="el-icon-remove" @click="formValue.deptIdsInput.splice(index, 1)" type="text"></el-button>
						</el-form-item>
					</el-col>
				</el-row>

				<ex_header_spiler :title="$tt('label_permission_config')" v-if="roleScope != 'DEFAULT'"></ex_header_spiler>

				<el-row v-if="roleScope != 'DEFAULT'">
					<el-col :span="2" style="max-height: 280px; overflow-y: scroll;">
						<div style="display: flex; padding-left: 20px; gap: 14px; line-height: 32px;">
							<div style="flex:1 ; text-align: left; font-weight: bold; ">{{ $tt('label_system_type') }}</div>
							<div style="width: 80px; font-weight: bold; text-align: center;  ">{{ $tt('label_enable_status') }}</div>
							<div style="width: 120px; text-align: center; font-weight: bold; ">{{ $tt('label_permission_level') }}</div>
							<div style="width: 300px; text-align: center; font-weight: bold;">{{ $tt('label_role_selection') }}</div>
						</div>

						<template v-if="finalRoleFormRows && finalRoleFormRows.length > 0">
							<div v-for="(item, index) in finalRoleFormRows" style="display: flex; padding-left: 20px; line-height: 42px; gap: 14px;">
								<div style="flex:1 ; overflow-x: hidden; white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">
									{{ item.userRoleSystem == 'WMS' ? 'WMS - ' + item.warehouseName : roleSystemMap[item.userRoleSystem] }}
								</div>
								<div style="width: 80px; text-align: center;  ">
									<el-switch v-model="item.userRoleStatus" active-value="ENABLE" inactive-value="DISABLED"> </el-switch>
								</div>
								<div style="width: 120px;">
									<el-select v-model="item.userRoleType" :placeholder="$tt('tip_please_select')" style="width: 100%;" :disabled="item.userRoleStatus == 'DISABLED'">
										<el-option key="ADMIN" :label="$tt('label_admin_user')" value="ADMIN"></el-option>
										<el-option key="OPERATOR" :label="$tt('label_operator_user')" value="OPERATOR"></el-option>
									</el-select>
								</div>
								<div style="width: 300px;">
									<el-select
										v-model="item.userRoleIds"
										:placeholder="$tt('tip_please_select')"
										style="width: 100%;"
										:disabled="item.userRoleStatus == 'DISABLED' || item.userRoleType == 'ADMIN'"
										multiple
									>
										<el-option v-for="subItem in companyRoleGroup[item.userRoleSystem]" :key="subItem.roleId" :label="subItem.roleName" :value="subItem.roleId"> </el-option>
									</el-select>
								</div>
							</div>
						</template>
					</el-col>
				</el-row>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogFormVisible = false">{{ $tt('label_cancel') }}</el-button>
				<el-button type="primary" @click="submitForm">{{ $tt('label_confirm') }}</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import superTablePageFunction from '@/mixin/super-table-page-function';

let moduleName = 'label_tms_user_user_manager';

export default {
	title: 'title_user_manage',
	components: {},
	mixins: [superTablePageFunction],

	data() {
		let _this = this;

		return {
			formModel: 'insert/update',

			roleSystemArr: [
				{ id: 'OMS', name: this.$tt('label_business_back_system') },
				{ id: 'WMS', name: this.$tt('label_wms_warehouse_system') },
				{ id: 'TMS', name: this.$tt('label_tms_transport_system') },
			],
			roleSystemMap: {},

			dialogFormVisible: false,
			dialogTitle: '',
			formValue: {
				deptIdInput: [],
				deptIdsInput: [],
			},
			rules: {
				companyName: [
					{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
					{ min: 3, max: 32, message: this.$tt('tip_length_in_min_max', { min: 3, max: 32 }), trigger: 'blur' },
				],
				companyShortCode: [
					{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
					{ min: 3, max: 16, message: this.$tt('tip_length_in_min_max', { min: 3, max: 16 }), trigger: 'blur' },
				],
				name: [
					{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
					{ min: 2, max: 16, message: this.$tt('tip_length_in_min_max', { min: 3, max: 16 }), trigger: 'blur' },
				],
				loginId: [
					{ required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
					{
						validator: (r, v, cb) => {
							if (!this.$reg.PureNumberLetterUnderline(v)) {
								return cb(this.$tt('tip_only_input_number_char_underline'));
							}
							cb();
						},
						trigger: 'blur',
					},
				],
			},

			companyArr: [],

			// 货代公司的角色信息
			companyRoleMap: {
				companyId: [
					{
						roleSystem: 'WMS',
						children: [
							{
								roleId: 11,
								roleName: 'role1',
							},
							{
								roleId: 22,
								roleName: 'role2',
							},
						],
					},
				],
			},

			userRoleMap: {},

			deptOptions: [],

			companyDataCfg: {},

			companyRoleGroup: {},

			finalRoleFormRows: [],

			showSyncDeptBtn: false,
			loadFromThirdTitle: '',
			thirdLoginType: '',
		};
	},

	watch: {
		'formValue.companyId'(val, old) {},
	},

	created() {
		let _this = this;

		_this.roleSystemMap = {};
		_this.roleSystemArr.forEach((e) => {
			_this.roleSystemMap[e.id] = e.name;
		});

		// 加载所有货代公司
		_this.$ajax({
			url: '/ums-api/user/UserCompanyRpc/loadCurrentCompanyRoles.json',
			success: (res) => {
				_this.companyArr = res.data.rows;
				if (res && res.data) {
					_this.companyDataCfg = res.data;
					_this.initFormRoleInfos();
				}
			},
		});

		// 加载第三方登陆配置
		_this.$ajax({
			url: '/ums-api/user/ThirdLoginConfigRpc/getConfig.json',
			data: {
				simple: true,
				roleScope: 'COMPANY',
			},
			success: (res) => {
				if (res && res.data) {
					let loginType = res.data.loginType;
					if (loginType == 'WECHAT') {
						_this.loadFromThirdTitle = '从企业微信同步用户信息';
					} else if (loginType == 'DINGDING') {
						_this.loadFromThirdTitle = '从钉钉同步用户信息';
					} else if (loginType == 'FEISHU') {
						_this.loadFromThirdTitle = '从飞书同步用户信息';
					}

					_this.showSyncDeptBtn = res.data.status == 'ENABLE';
					_this.thirdLoginType = loginType;
				}
			},
		});

		_this.loadDeptTree();

		_this.option = {
			search: {
				model: [
					{ label: 'label_keyword', key: 'keyword' },
					{
						label: 'label_status',
						key: 'status',
						type: 'select',
						enum: 'UserStatusEnum',
					},
				],
			},
			action: [
				{
					label: this.roleScope != 'DEFAULT' ? this.$tt('label_add_user') : this.$tt('label_add_admin'),
					attrs: { icon: 'el-icon-plus' },
					click: () => {
						this.formModel = 'insert';
						this.dialogTitle = this.$tt('label_add_user');
						if (this.roleScope == 'DEFAULT') {
							this.dialogTitle = this.$tt('label_add_admin');
						}
						this.dialogFormVisible = true;
						this.formValue = {
							companyId: this.$currentAgentId,
							deptIdInput: [],
							deptIdsInput: [],
							roleInfos: [],
						};

						this.resetUserRoleForm(this.formValue);
					},
				},
			],

			actionExtra: [
				{
					label: () => {
						return _this.loadFromThirdTitle;
					},
					if: () => {
						return _this.showSyncDeptBtn;
					},
					click: () => {
						_this
							.$confirm('确定' + _this.loadFromThirdTitle + '?', '提示', {
								confirmButtonText: '确定',
								cancelButtonText: '取消',
								type: 'warning',
							})
							.then(() => {
								_this.$ajax({
									url: '/ums-api/user/ThirdLoginConfigRpc/sync_users.json',
									success: (res) => {
										_this.$message({
											type: 'success',
											message: '同步任务提交成功，请耐心等待',
										});
									},
								});
							})
							.catch(() => {});
					},
				},
			],

			table: {
				url: '/ums-api/user/UserInfoRpc/list.json?roleSystem=' + this.roleSystem + '&roleScope=' + this.roleScope,
				attrs: {
					'cell-style': ({ row, column, rowIndex, columnIndex }) => {
						if (column.property == 'status') {
							return { color: row.status == 'NORMAL' ? this.$globalCss.successColor : this.$globalCss.infoColor };
						}
					},
				},
				model: [
					{ key: 'loginId', label: 'label_login_account', align: 'left', minWidth: 100 },
					{ key: 'name', label: 'label_user_name', align: 'left', minWidth: 100 },
					{
						key: 'deptId',
						label: '部门',
						align: 'left',
						'show-overflow-tooltip': true,
						minWidth: 100,
						attrs: {
							formatter: (r, c, v, i) => {
								let letArr = [];

								let existDeptId = {};
								if (r['deptId']) {
									letArr.push(_this.deptNameCache[r['deptId']]);
									existDeptId[r['deptId']] = true;
								}

								if (r['deptIds'] && r['deptIds'].length > 0) {
									r['deptIds'].forEach((dpId) => {
										if (existDeptId[dpId]) {
											return;
										}
										existDeptId[dpId] = true;
										letArr.push(_this.deptNameCache[dpId]);
									});
								}
								return letArr.join(', ');
							},
						},
					},
					{
						key: 'roleInfos',
						label: 'label_role_info',
						align: 'left',
						minWidth: 100,
						if: function() {
							return _this.roleScope != 'DEFAULT';
						},
						'show-overflow-tooltip': true,
						attrs: {
							formatter: (r, c, v, i) => {
								if (v && v.length > 0) {
									v = v.filter((ee) => ee.userRoleStatus == 'ENABLE');

									if (this.roleSystem == 'TMS') {
										v = v.filter((ee) => ee.userRoleSystem == 'TMS');
									}
									// WMS
									if (this.roleSystem == 'WMS') {
										v = v.filter((ee) => ee.userRoleSystem == 'WMS' && this.$loginUser.currentWarehouseId == ee.warehouseId);
									}

									let returnArr = [];
									v.forEach((vv) => {
										let str = '';
										if (_this.roleSystem === 'OMS' || _this.roleSystem === 'ALL') {
											str = vv.userRoleSystem == 'WMS' ? 'WMS - ' + vv.warehouseName : this.roleSystemMap[vv.userRoleSystem];
											str = '[' + str + '] ';
										}
										if (vv.userRoleType == 'ADMIN') {
											str += _this.$tt('label_admin_user');
										} else {
											if (vv.userRoleIds) {
												let roleNames = vv.userRoleIds.map((kk) => _this.userRoleMap[kk]).join(', ');
												str += roleNames;
											}
										}
										returnArr.push(str);
									});

									return returnArr.join('  ');
								}
								return '';
							},
						},
					},
					{
						key: 'status',
						label: 'label_status',
						minWidth: 100,
						attrs: {
							formatter: (r, c, v, i) => {
								return this.$enumShow(v, 'UserStatusEnum');
							},
						},
					},
					{ key: 'mobile', label: '扩展信息', align: 'left', minWidth: 100, slot: 'userExtend' },
					{
						key: 'gmtCreate',
						label: 'label_create_time',
						minWidth: 100,
						attrs: {
							formatter: (r, c, v, i) => {
								return this.$dateFormat(v);
							},
						},
					},
					{
						type: 'operate',
						width: 220,
						operate: [
							{
								label: 'label_reset_password',
								type: 'confirm-button',
								message: 'tip_reset_password_confirm',
								url: '/ums-api/user/UserInfoRpc/resetPwd.json',
								params: (v) => {
									return { securityId: v.securityId };
								},
								done: [
									'tip',
									(row, i, data, res) => {
										this.afterPwdReset(res);
									},
								],
							},
							{
								label: 'label_freeze',
								type: 'confirm-button',
								message: 'tip_freeze_user_confirm',
								buttonClass: 'button_text_warning',
								confirmButtonType: 'warning',
								url: '/ums-api/user/UserInfoRpc/freeze.json',
								if: (row) => {
									return row.status == 'NORMAL';
								},
								params: (v) => {
									return { securityId: v.securityId, type: 'freeze' };
								},
								done: ['reload', 'tip'],
							},
							{
								label: 'label_unfreeze',
								type: 'confirm-button',
								message: 'tip_unfreeze_user_confirm',
								url: '/ums-api/user/UserInfoRpc/freeze.json',
								if: (row) => {
									return row.status != 'NORMAL';
								},
								params: (v) => {
									return { securityId: v.securityId, type: 'unfreeze' };
								},
								done: ['reload', 'tip'],
							},
							{
								label: 'label_edit',
								if: (row) => this.roleScope != 'DEFAULT',
								click: (row) => {
									let _this = this;

									this.formModel = 'update';
									this.dialogTitle = this.$tt('label_edit_user');
									if (this.roleScope == 'DEFAULT') {
										this.dialogTitle = this.$tt('label_edit_admin');
									}

									let tmpObj = JSON.parse(JSON.stringify(row));
									if (!tmpObj.deptIdInput) {
										tmpObj.deptIdInput = [];
									}
									if (!tmpObj.deptIdsInput) {
										tmpObj.deptIdsInput = [];
									}

									// 角色表单填充
									this.resetUserRoleForm(tmpObj);

									this.formValue = tmpObj;
									this.dialogFormVisible = true;
								},
							},
							{
								label: 'label_delete',
								type: 'confirm-button',
								url: '/ums-api/user/UserInfoRpc/delete.json',
								buttonClass: 'button_text_danger',
								confirmButtonType: 'danger',
								message: 'label_fms_bank_card_confirm_delete',
								if: (row) => this.roleScope != 'DEFAULT',
								params: (v) => {
									return { securityId: v.securityId };
								},
								done: ['reload', 'tip'],
							},
						],
					},
				],
			},
		};
	},

	props: {
		// admin  compnay
		roleScope: {
			type: String,
			defafult: '',
		},

		// WMS OMS TMS
		roleSystem: {
			type: String,
			defafult: '',
		},
	},

	destroyed() {},

	methods: {
		cacheDeptNames(depts) {
			let _this = this;

			if (!depts || depts.length == 0) {
				return;
			}
			depts.forEach((rr) => {
				_this.deptNameCache[rr.id] = rr.name;

				_this.cacheDeptNames(rr.children);
			});
		},

		loadDeptTree() {
			let _this = this;

			_this.deptNameCache = {};

			_this.$ajax({
				url: '/ums-api/user/UserDeptRpc/currentUserOptionalDepts.json',
				success: (res) => {
					if (res && res.data && res.data.rows) {
						_this.deptOptions = res.data.rows;

						_this.cacheDeptNames(_this.deptOptions);
					}
				},
			});
		},

		// 初始化角色表单
		initFormRoleInfos() {
			let _this = this;

			let rr = _this.companyDataCfg;

			let companyRoleGroup = {};

			// 建立缓存对象
			rr.roleList.forEach((role) => {
				if (!companyRoleGroup[role.roleSystem]) {
					companyRoleGroup[role.roleSystem] = [];
				}
				companyRoleGroup[role.roleSystem].push({
					roleId: role.roleId,
					roleName: role.roleName,
				});
				_this.userRoleMap[role.roleId] = role.roleName;
			});

			// 用户编辑时的角色列表
			let finalRoleFormRows = [];

			if (companyRoleGroup['OMS']) {
				finalRoleFormRows.push({
					_id: 'OMS',
					userRoleSystem: 'OMS',
					userRoleType: 'OPERATOR',
					userRoleIds: [],
					userRoleName: '',
					userRoleStatus: 'DISABLED',
					warehouseId: '',
					warehouseCode: '',
					warehouseName: '',
				});
			}

			if (companyRoleGroup['TMS']) {
				finalRoleFormRows.push({
					_id: 'TMS',
					userRoleSystem: 'TMS',
					userRoleType: 'OPERATOR',
					userRoleIds: [],
					userRoleName: '',
					userRoleStatus: 'DISABLED',
					warehouseId: '',
					warehouseCode: '',
					warehouseName: '',
				});
			}

			if (companyRoleGroup['WMS'] && rr.warehouseList) {
				let warehouseChooseArr = [];
				rr.warehouseList.forEach((wh) => {
					finalRoleFormRows.push({
						_id: 'WMS_' + wh.warehouseId,
						userRoleSystem: 'WMS',
						userRoleType: 'OPERATOR',
						userRoleIds: [],
						userRoleName: '',
						userRoleStatus: 'DISABLED',
						warehouseId: wh.warehouseId,
						warehouseCode: wh.warehouseCode,
						warehouseName: wh.warehouseName,
					});
				});
			}

			if (_this.roleSystem === 'TMS') {
				finalRoleFormRows = finalRoleFormRows.filter((ee) => ee.userRoleSystem == 'TMS');
			}
			if (_this.roleSystem === 'WMS') {
				finalRoleFormRows = finalRoleFormRows.filter((ee) => {
					return ee.userRoleSystem == 'WMS' && ee.warehouseId == _this.$loginUser.currentWarehouseId;
				});
			}

			_this.finalRoleFormRows = finalRoleFormRows;
			_this.companyRoleGroup = companyRoleGroup;
		},

		// 根据当前新增操作、 填充角色表单
		resetUserRoleForm(formRow) {
			let _this = this;

			let formRoleMap = {};
			let formRoles = formRow.roleInfos;
			if (formRoles && formRoles.length > 0) {
				formRoles.forEach((r) => {
					let _id = r.userRoleSystem + (r.warehouseId ? '_' + r.warehouseId : '');
					formRoleMap[_id] = r;
				});
			}

			_this.finalRoleFormRows.forEach((fr) => {
				let editR = formRoleMap[fr['_id']];
				if (editR) {
					fr['userRoleType'] = editR['userRoleType'];
					fr['userRoleIds'] = editR['userRoleIds'] ? editR['userRoleIds'] : [];
					if (fr['userRoleType'] == 'ADMIN') {
						fr['userRoleIds'] = [];
					}
					fr['userRoleStatus'] = editR['userRoleStatus'];
				} else {
					fr['userRoleType'] = 'OPERATOR';
					fr['userRoleIds'] = [];
					fr['userRoleStatus'] = 'DISABLED';
				}
			});
		},
		afterPwdReset(res) {
			const h = this.$createElement;
			let id = 'pwdMsgbox';
			this.$msgbox({
				title: this.$t('label_tip'),
				type: 'success',
				message: h('div', { attrs: { id } }, [
					h('div', { class: 'flex_row_wrap_center' }, [h('div', { class: 'mg_r1', style: 'font-size:15px;font-weight: bold;' }, [res.data.loginId]), this.$t('tip_password_reset_success')]),
					h('div', { class: 'flex_row_wrap_center' }, [
						this.$t('tip_new_password_is'),
						h('div', { class: 'mg_h1', style: 'font-size:15px;font-weight: bold;' }, [res.data.pwd]),
						h('el-button', { props: { size: 'mini', type: 'text' }, on: { click: (e) => this.$copyToClip(res.data.pwd, this.$t('label_has_copy'), id) } }, [this.$t('label_copy_password')]),
					]),
				]),
			})
				.then(() => {})
				.catch((e) => {});
		},

		submitForm() {
			let _this = this;

			let mainDept = _this.formValue.deptIdInput;
			let addDept = _this.formValue.deptIdsInput;
			if (addDept.length > 0 && (!mainDept || mainDept.length == 0)) {
				_this.$message({ type: 'error', message: '请先设置主部门' });
			}

			_this.$refs['formEl'].validate((valid) => {
				if (valid) {
					_this.formValue.roleInfos = _this.finalRoleFormRows;
					_this.formValue.roleScope = _this.roleScope;
					_this.formValue.roleSystem = _this.roleSystem;

					_this.$ajax({
						url: '/ums-api/user/UserInfoRpc/saveUpdate.json',
						type: 'json',
						data: _this.formValue,
						success: (responseData) => {
							this.$message({
								showClose: true,
								message: this.$tt('tip_submit_success'),
								type: 'success',
							});
							_this.$refs['SuperTablePage'].reload();
							_this.dialogFormVisible = false;
						},
					});
				} else {
					return false;
				}
			});
		},
	},
};
</script>
<style>
.small-btn span {
	font-size: 14px;
}

.small-btn .el-button--small span {
	font-size: 14px;
}
</style>
